package di

import (
	"github.com/mix-go/xdi"
	"hy_808/logdot"
	"os"
	"path/filepath"
)

func init() {
	obj := xdi.Object{
		Name: "logdot",
		New: func() (interface{}, error) {
			var ProgramDir = func() string {
				path, _ := filepath.Abs(os.Args[0])
				return filepath.Dir(path) + logdot.PathSep
			}()
			logger := logdot.Create(logdot.Option{
				Dir:    ProgramDir + "runtime/",
				File:   "log/2006-01-02/server/2006-01-02 15.log",
				Stdout: true,
				SpecificFile: map[string]string{
					"program": "run.info",
					"sql":     "log/2006-01-02/sql/2006-01-02 15.log",
				},
			})
			return logger, nil
		},
	}
	if err := xdi.Provide(&obj); err != nil {
		panic(err)
	}
}

func Logdot() (logger *logdot.Logdot) {
	if err := xdi.Populate("logdot", &logger); err != nil {
		panic(err)
	}
	return
}
